package com.barry.pattern.singleton;

/**
 * 类功能描述：
 * @author WangXueXing create at 19-9-4 下午10:15
 * @version 1.0.0
 */
public class ThreadLocalSingle {
    private static final ThreadLocal<ThreadLocalSingle> tlSingleton =
            ThreadLocal.withInitial(() -> {
                return new ThreadLocalSingle();
            });
    /**
     * Get the focus finder for this thread.
     */
    public static ThreadLocalSingle getInstance() {
        return tlSingleton.get();
    }
    // enforce thread local access
    private ThreadLocalSingle() {}

    public static void main(String[] args) {
        ThreadLocalSingle a = ThreadLocalSingle.getInstance();
        ThreadLocalSingle b = ThreadLocalSingle.getInstance();
        System.out.println((a==b));
    }
}
